﻿package appLoader.data {
	
	public class HashTable3 {
		
		private var _keys		:Array;
		private var _values		:Array;
		private var _values2	:Array;
		
		public function HashTable3() {
			_keys 		= new Array();
			_values 	= new Array();
			_values2	= new Array();
		}
		
		public function put(key:Object, value:Object, value2:Object = null):void {
			var index:Number = _keys.indexOf(key);
			if (index > - 1) {
				_values[index] 	= value;
				_values2[index] = value2
			} else {
				_keys.push(key);
				_values.push(value);
				_values2.push(value2);
			}
		}
		
		public function putValue2ByKey(key:Object, value2:Object):Boolean {
			var index:Number = _keys.lastIndexOf(key);
			if (index > -1) {
				_values2[index] = value2;
				return true;
			}
			trace("Tentando associar um value2 mas o key não foi encontrado");
			return false;
		}
		
		public function removeByKey(key:Object):Object {
			var index:Number = _keys.indexOf(key)
			if (index > -1) {
				return removeByIndex(index)
			}
			return null
		}
		
		public function removeByValue(value:Object):Object{
			var index:Number = _values.indexOf(value);
			if(index >-1){
				return removeByIndex(index)
			}
			return null
		}
		
		public function removeByValue2(value2:Object):Object{
			var index:Number = _values2.indexOf(value2);
			if(index >-1){
				return removeByIndex(index)
			}
			return null
		}
		
		public function removeByIndex(index:int):Object{
			if (index < length()) {
				_keys.splice(index, 1)
				_values2.splice(index, 1);
				return _values.splice(index,1)
			}
			return null;
		}
		
		//
		public function getKey(value:Object):Object {
			var index:Number = _values.indexOf(value);
			if (index > - 1) {
				return _keys[index];
			}
			return (null);
		}
		//
		public function getValueByIndex(index:Number):Object {
			if (index < length()) {
				return _values[index];
			}
			return null;
		}
		//
		public function getValue2ByIndex(index:Number):Object {
			if (index < length()) {
				return _values2[index];
			}
			return null;
		}
		//
		public function getKeyByIndex(index:Number):Object {
			if (index < length()) {
				return _keys[index];
			}
			return null;
		}
		//
		public function get(key:Object):Object {
			return getValue(key);
		}
		//
		public function getValue(key:Object):Object {
			var index:Number = _keys.indexOf(key);
			if (index > - 1) {
				return _values[index];
			}
			return null;
		}
		public function getValue2(key:Object):Object {
			var index:Number = _keys.indexOf(key);
			if (index > - 1) {
				if (_values2[index] != undefined) {
					return _values2[index];
				}
			}
			return null;
		}
		
		public function getValue2ByValue(value:Object):Object {
			var index:Number = _values.indexOf(value);
			if (index > - 1) {
				if (_values2[index] != undefined) {
					return _values2[index];
				}
			}
			return null;
		}
		
		public function getValueByValue2(value2:Object):Object {
			var index:Number = _values2.indexOf(value2);
			if (index > - 1) {
				if (_values[index] != undefined) {
					return _values[index];
				}
			}
			return null;
		}
		//
		public function getValues():Array{
			return _values
		}
		//
		public function getValues2():Array{
			return _values2
		}
		public function getKeys():Array{
			return _keys
		}
		//
		public function clear():void{
			_keys 		= new Array();
			_values 	= new Array();
			_values2 	= new Array();
		}
		//
		public function length():int {
			return int(_keys.length);
		}
		public function isEmpty():Boolean{
			return	_keys.length > 0
		}
		
		public function toString():String {
			var s:String = "\n[HashTable 3]";
			s += "keys: " + _keys + "\n";
			s += "values: " + _values + "\n";
			s += "values2: " + _values2 + "\n";
			return s;
		}
	}
}
